<!DOCTYPE HTML>
<html>
  <head>
    <title>Kunuki</title>
        <link rel="SHORTCUT ICON" href="img/favicon.ico" />
        <script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;key="></script>
        <script type="text/javascript" src="jquery/jquery-1.7.1.min.js"></script>
        <script type="text/javascript" src="jquery/jquery.gmap-1.1.0-min.js"></script>
        <script type="text/javascript" src="jquery/jquery.gmap-1.1..js"></script>
        <script type="text/javascript" src="jquery/slides.jquery.js"></script>          
				<link rel="stylesheet" href="css/style.css" />
        <link rel="stylesheet" href="css/grid-12.css" />
        <meta name="description" content="clothing" />
				<meta name="keywords" content="kunuki, kidswerar, girlswear, womenswear, accessories, assamese, guwahati clothings" />
				<meta name="author" content="Tigmaminds" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <script type="text/javascript" language="javascript">
          $('document').ready(function() {
    		});        
				</script>
  </head>
  <body>
    <div id="container" class="container_12">
    
    <?php
    include("inc/db.class.php");
    require("php/header.php");
    $database = new database();
    ?>
		  <div id="line" class="grid_12"></div>
      <div id="slides" class="grid_12">
	  
	  <iframe></iframe>

<?php

// Get the access token with app_id and app_secret
$url1 = 'https://graph.facebook.com/oauth/access_token';
$data1 = array('client_id' => '1400579473536370',
	'client_secret'=>'f04119d661b07e1b8fd2ab9ebd18d204',
	'grant_type'=>'client_credentials'
);
$getAccessTokenResult = explode('=',curlUsingGet($url1, $data1));
$access_token = $getAccessTokenResult['1'];


// Get the posts
$url2 = 'https://graph.facebook.com/SmartekConsultancy';
$data2 = array(
'fields'=>'posts.limit(15)',
'access_token'=>$access_token
);

$static_url="http://www.facebook.com/photo.php?fbid=590835637658064&set=a.590835327658095.1073741853.154625137945785&type=1&relevant_count=58";
// Print the result array
echo "<pre>";
$str = staticUrl($static_url);
$fbpost = json_decode(curlUsingGet($url2, $data2));
echo $posts_title = $fbpost->posts->data[0]->name;
echo $likes = count($fbpost->posts->data[0]->likes->data);

echo "</pre>";


$posts = $fbpost->posts->data;

foreach($posts as $post)
{
if(isset($post->name))
	{
		echo "<br>post title = ".$post->name;
		if(isset($post->picture))
			echo "<br><img src=".$post->picture." width='150'/>";
		
	}
	else
	{
		echo "<br>".$post->id;
	}
}

$result = curlUsingGet($url2, $data2);

echo "<pre>";
print_r($fbpost);

echo "</pre>";
function curlUsingGet($url, $data)
{

    if(empty($url))
    {
        return 'Error: invalid Url or Data';
    }

	//url-ify the data for the POST
	$fields_string = '';
	foreach($data as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
	$fields_string = rtrim($fields_string,'&');


	//open connection
	$ch = curl_init();
	$url = $url."?".$fields_string;
	echo "<br>url to hit".$url."</br><br>";


	curl_setopt($ch,CURLOPT_URL,$url);


	curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10); # timeout after 10 seconds, you can increase it
	//curl_setopt($ch,CURLOPT_HEADER,false);
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);  # Set curl to return the data instead of printing it to the browser.
	curl_setopt($ch,  CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); # Some server may refuse your request if you dont pass user agent

	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

	//execute post
	$result = curl_exec($ch);

	//close connection
	curl_close($ch);
	return $result;
}


function staticUrl($url)
{

    if(empty($url))
    {
        return 'Error: invalid Url or Data';
    }

	//open connection
	$ch = curl_init();
	//$url = $url."?".$fields_string;
	curl_setopt($ch,CURLOPT_URL,$url);
	curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10); # timeout after 10 seconds, you can increase it
	//curl_setopt($ch,CURLOPT_HEADER,false);
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);  # Set curl to return the data instead of printing it to the browser.
	curl_setopt($ch,  CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); # Some server may refuse your request if you dont pass user agent

	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

	//execute post
	$result = curl_exec($ch);

	//close connection
	curl_close($ch);
	return $result;
}
?>
				
      </div>
      <?php require("php/footer.php"); ?>
    </div>
  </body>
</html>
